package com.lcg.liteflow.web;

import com.alibaba.fastjson.JSON;
import com.lcg.liteflow.chain2.ParamMap;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.flow.LiteflowResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @author: LCG
 * @date: 2023-03-22 13:50:58
 * @description: 测试规则引擎的使用
 **/
@RestController
@RequestMapping("exec")
public class FlowExectuerController {

    @Resource
    private FlowExecutor flowExecutor;

    @Qualifier("threadLocal1")
    @Autowired
    private ThreadLocal<String> threadLocal;

    @RequestMapping("test1")
    public String testExec(){
        threadLocal.set("213312312");
        flowExecutor.execute2Resp("chain1");
        return null;
    }

    @RequestMapping("test2")
    public String testExec2(){
        //这里通过chain2链条测试  规则节点之前的参数传递
        ParamMap paramMap=new ParamMap();
        paramMap.setStartDate(new Date());
        paramMap.setUserName("张三1323");
        LiteflowResponse response = flowExecutor.execute2Resp("chain2", paramMap,ParamMap.class);
        System.out.println(JSON.toJSONString(response.getExecuteSteps()));
        System.out.println("chain2执行完毕的结果："+paramMap.getResponse());
        return null;
    }



}
